<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>
			兄弟海鲜管理系统
		</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="./css/x-admin.css" media="all">

		<link href="css/xtiper.css" type="text/css" rel="stylesheet" />
		<script src="js/xtiper.min.js" type="text/javascript"></script>

	</head>

	<body onload="findall()">
		<div class="x-nav">
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="x-body">
			<div style="margin-bottom: 15px;">
				<label class="layui-form-label">查询订单</label>
				<div class="layui-input-inline">
					<input type="text" id="orderRandom" name="orderRandom" placeholder="订单号" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-input-inline" style="width:80px">
					<button class="layui-btn" onclick="search()"><i class="layui-icon">&#xe615;</i></button>
				</div>
			</div>
			<xblock>
				<button class="layui-btn layui-btn-danger" onclick="batchsure()">
            		<i class="layui-icon">&#xe640;</i>批量确认</button>
				<span class="x-right" style="line-height:40px">共有数据：<a id="total" name="total"></a> 条</span>
			</xblock>
			<table class="layui-table">
				<thead>
					<tr>
						<th>
							<input type="checkbox" name="" value="">
						</th>
						<th>
							ID
						</th>
						<th>
							订单号
						</th>
						<th>
							订单内容
						</th>
						<th>
							订单时间
						</th>
						<th>
							订单总价
						</th>
						<th>
							订单状态
						</th>
						<th>
							操作
						</th>
					</tr>
				</thead>
				<tbody id="orderslist">
				</tbody>
			</table>
			<div id="page"></div>
		</div>
		<script src="./lib/layui/layui.js" charset="utf-8"></script>
		<script src="./js/x-layui.js" charset="utf-8"></script>

		<script type="text/javascript">
			layui.use(['layer', 'laypage'], function() {
				layer = layui.layer; //弹出层
				laypage = layui.laypage; //分页
				laypage({
					cont: 'page',
					pages: 100,
					first: 1,
					last: 100,
					prev: '<em><</em>',
					next: '<em>></em>',
					jump: function(obj) {
						var pageNmber = obj.curr;
						findall2(pageNmber);
					}
				});
			});

			function search() {
				var orderRandom = $("#orderRandom").val();
				var settings = {
					"url": "http://127.0.0.1:8080/order/findPage.do?page=1&size=100&stateName=未确认",
					"method": "POST",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
					"data": JSON.stringify({
						"name": orderRandom
					}),
				};

				$.ajax(settings).done(function(response) {
					if(response != "") {
						$("#orderslist").empty();
						var a = 0;
						var msg = "";
						for(var i = 0; i < response.list.length; i++) {
							a = a + 1;
							msg += '<tr> <td>';
							msg += '<input type=\"checkbox\" value=\"' + response.list[i].orderId + '\" id=\"orderId\" name=\"orderId\"></td> ';
							msg += '<td>' + a + '</td> ';
							msg += '<td>' + response.list[i].orderId + '</td>';
							msg += '<td><u style=\"cursor:pointer\"  onclick=\"detailorder(' + response.list[i].orderId + ')\">点击查看详细订单</u></td>';
							msg += ' <td >' + response.list[i].orderTime + '</td>';
							msg += ' <td >' + response.list[i].orderTotal + '</td>';
							msg += ' <td ><span class=\"layui-btn layui-btn-normal layui-btn-mini\" style=\"background-color: #AC2925;\">' + response.list[i].state.stateName + '</span></td>';
							msg += '<td class=\"td-manage\"> ';
							msg += ' <a title=\"确认订单\" href=\"javascript:;\" class=\"ml-5\" style=\"text-decoration:none\" onclick=\"sureorder(' + response.list[i].orderId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/确认.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += '<a class=\"xbutton\" title=\"反馈订单\"  onclick=\"xtip.alert(' + response.list[i].customer.customerNumber + ')\">';
							msg += '<i><img src=\"images/反馈信息.png\" style=\"width: 25;\" height=\"25\"></i>';
							msg += '</a> </td> </tr>';
						}
						$("#orderslist").html(msg);
					} else {
						xtip.msg('失败', {
							times: 1
						});
					}
				});
			}
		</script>
		<script type="text/javascript">
			function findall() {
				var url = 'http://127.0.0.1:8080/order/findstate.do?page=1&size=10&stateName=未确认';
				$.ajax({
					type: "get", //post方式传输，比get更加密安全
					url: url, //请求地址
					contentType: "application/json;charsetset=UTF-8",
					success: function(data) {
						$('#total').text(data.total);
						var a = 0;
						var msg = "";
						for(var i = 0; i < data.list.length; i++) {
							a = a + 1;
							msg += '<tr> <td>';
							msg += '<input type=\"checkbox\" value=\"' + data.list[i].orderId + '\" id=\"orderId\" name=\"orderId\"></td> ';
							msg += '<td>' + a + '</td> ';
							msg += '<td>' + data.list[i].orderId + '</td>';
							msg += '<td><u style=\"cursor:pointer\"  onclick=\"detailorder(' + data.list[i].orderId + ')\">点击查看详细订单</u></td>';
							msg += ' <td >' + data.list[i].orderTime + '</td>';
							msg += ' <td >' + data.list[i].orderTotal + '</td>';
							msg += ' <td ><span class=\"layui-btn layui-btn-normal layui-btn-mini\" style=\"background-color: #AC2925;\">' + data.list[i].state.stateName + '</span></td>';
							msg += '<td class=\"td-manage\"> ';
							msg += ' <a title=\"确认订单\"  class=\"ml-5\" style=\"text-decoration:none\" onclick=\"sureorder(' + data.list[i].orderId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/确认.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += '<a class=\"xbutton\" title=\"反馈订单\"  onclick=\"xtip.alert(' + data.list[i].customer.customerNumber + ')\">';
							msg += '<i><img src=\"images/反馈信息.png\" style=\"width: 25;\" height=\"25\"></i>';
							msg += '</a> </td> </tr>';
						}
						$("#orderslist").html(msg);
					},
					error: function() {
						alert("失败");
					}
				})
			}

			function findall2(pageNmber) {
				var url = 'http://127.0.0.1:8080/order/findstate.do?page=' + pageNmber + '&size=10&stateName=未确认';
				$.ajax({
					type: "get", //post方式传输，比get更加密安全
					url: url, //请求地址
					contentType: "application/json;charsetset=UTF-8",
					success: function(data) {
						$('#total').text(data.total);
						var a = 0;
						var msg = "";
						for(var i = 0; i < data.list.length; i++) {
							a = a + 1;
							msg += '<tr> <td>';
							msg += '<input type=\"checkbox\" value=\"' + data.list[i].orderId + '\" id=\"orderId\" name=\"orderId\"></td> ';
							msg += '<td>' + a + '</td> ';
							msg += '<td>' + data.list[i].orderId + '</td>';
							msg += '<td><u style=\"cursor:pointer\"  onclick=\"detailorder(' + data.list[i].orderId + ')\">点击查看详细订单</u></td>';
							msg += ' <td >' + data.list[i].orderTime + '</td>';
							msg += ' <td >' + data.list[i].orderTotal + '</td>';
							msg += ' <td ><span class=\"layui-btn layui-btn-normal layui-btn-mini\" style=\"background-color: #AC2925;\">' + data.list[i].state.stateName + '</span></td>';
							msg += '<td class=\"td-manage\"> ';
							msg += ' <a title=\"确认订单\"  class=\"ml-5\" style=\"text-decoration:none\" onclick=\"sureorder(' + data.list[i].orderId + ')\">';
							msg += '<i class=\"layui-icon\"><img src=\"images/确认.png\" style="width: 30;\" height=\"30\"></i>';
							msg += '</a>';
							msg += ' &nbsp;&nbsp;';
							msg += '<a class=\"xbutton\" title=\"反馈订单\"  onclick=\"xtip.alert(' + data.list[i].customer.customerNumber + ')\">';
							msg += '<i><img src=\"images/反馈信息.png\" style=\"width: 25;\" height=\"25\"></i>';
							msg += '</a> </td> </tr>';
						}
						$("#orderslist").html(msg);
					},
					error: function() {
						alert("失败");
					}
				})
			}
		</script>
		<script src="js/jquery.min.js"></script>
		<script type="text/javascript">
			function sureorder(orderId) {
				var url = 'http://127.0.0.1:8080/order/update';
				$.ajax({
					type: "post", //post方式传输，比get更加密安全
					url: url, //请求地址
					data: JSON.stringify({
						"orderId": orderId,
						"state": {
							"stateName": "已确认"
						}
					}), //打包data
					dataType: "json",
					contentType: "application/json;charsetset=UTF-8",
					success: function(data) {
						xtip.msg('确认成功')
						location.href = "./order-list-unsure.html";
					},
					error: function() {
						alert("失败");
					}
				})
			}
		</script>

		<script type="text/javascript">
			layui.use(['layer'], function() {
				layer = layui.layer; //弹出层
			});

			function detailorder(orderId) {
				var url = 'http://127.0.0.1:8080/order/finddetail?orderId=' + orderId;
				$.ajax({
					type: "post", //post方式传输，比get更加密安全
					url: url, //请求地址
					success: function(data) {
						for(var i = 0; i < data.length; i++) {
							sessionStorage.setItem(i, JSON.stringify(data[i]));
						}
						x_admin_show("用户编辑", './detailshow.html', '600', '500');
					},
					error: function() {
						alert("失败");
					}
				})
			}
		</script>
		<script type="text/javascript">
			function batchsure() {
				var arr = [];
				$("input:checkbox[name='orderId']:checked").each(function() {
					arr.push($(this).val());
				});
				var settings = {
					"url": "http://127.0.0.1:8080/order/batchupdate",
					"method": "POST",
					"timeout": 0,
					"headers": {
						"Content-Type": "application/json"
					},
					"data": JSON.stringify(arr),
				};

				$.ajax(settings).done(function(response) {

					xtip.msg('确认成功')
					location.href = "./order-list-unsure.html";
				});
			}
		</script>

	</body>

</html>